/* #include "ReadyQueue.h" */
#include "PthreadPool.h"


int main(int argc,const char * args[])
{
    if(argc < 2){
        printf("参数输入错误！\n");
        return 0;
    }
    PthreadPool pp;
    if(atoi(args[1]) < 2 ){
        printf("至少开启两个线程！\n");
        return 0;
    }
    pthreadPoolInit(&pp,atoi(args[1]));

    int sockfd = createSockfd("192.168.220.128","8888");
    listen(sockfd,10);
    int epollfd = epoll_create(1);
    addEpollNode(epollfd,sockfd);
    struct epoll_event ready_epoll[4096];
    while(1){
        int readyfd = epoll_wait(epollfd,ready_epoll,4096,-1);
        for(int i = 0 ; i < readyfd ; ++i){
            if(ready_epoll[i].data.fd == sockfd){
                int netfd = accept(sockfd,NULL,NULL);
                pthread_mutex_lock(&pp.lock1);
                    addQueueNode(&pp.rdy_que,netfd);
                    pthread_cond_broadcast(&pp.cond);
                pthread_mutex_unlock(&pp.lock1);
            } 
        }
    }
    return 0;
}

